<template>
  <div class="home-root flex flex-col bg-black">
    <!-- 顶部导航 -->
    <div class="nav-bar">
      <div class="tab-list">
        <div @click="activeTab = 'watching'" :class="['tab-item', { active: activeTab === 'watching' }]">
          <span class="tab-title">在追</span>
        </div>

        <div @click="activeTab = 'playlist'" :class="['tab-item', { active: activeTab === 'playlist' }]">
          <span class="tab-title">剧单</span>
        </div>

        <div @click="activeTab = 'featured'" :class="['tab-item', { active: activeTab === 'featured' }]">
          <span class="tab-title">精选</span>
        </div>
      </div>
      <button class="nav-btn" @click="handleNavBtnClick">
        <i
          :class="[
            'fas',
            activeTab === 'watching' ? (isEditMode ? 'fa-times' : 'fa-edit') : isSearchMode ? 'fa-times' : 'fa-search'
          ]"
        />
      </button>
    </div>

    <!-- 内容区域 -->
    <div class="content-area bg-black pt-16">
      <!-- 在追 -->
      <WatchingTab v-if="activeTab === 'watching'" :is-edit-mode="isEditMode" @exit-edit-mode="isEditMode = false" />

      <!-- 剧单 -->
      <PlaylistTab v-if="activeTab === 'playlist'" />

      <!-- 精选 -->
      <FeaturedTab v-if="activeTab === 'featured'" :active-tab="activeTab" @tab-change="activeTab = $event" />
    </div>
  </div>
</template>

<script setup>
import WatchingTab from './components/WatchingTab.vue'
import PlaylistTab from './components/PlaylistTab.vue'
import FeaturedTab from './components/FeaturedTab.vue'
import { useUserStore } from '@/stores/user.js'

const router = useRouter()

const userStore = useUserStore()
const activeTab = ref(userStore.token ? 'watching' : 'playlist')
const isEditMode = ref(false)
const isSearchMode = ref(false)

// 处理导航按钮点击
const handleNavBtnClick = () => {
  if (activeTab.value === 'watching') {
    isEditMode.value = !isEditMode.value
  } else {
    router.push('/search')
  }
}
</script>

<style scoped lang="scss">
.home-root {
  width: 100%;
  height: 100vh;
  min-height: 100vh;
  background: #000;
  color: #fff;
}

.nav-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1rem 0;
  width: 100%;
  position: fixed; /* 改为 sticky 定位 */
  top: 0; /* 距离顶部0像素 */
  z-index: 10; /* 设置较高的z-index，让导航栏浮在视频上方 */
  background: rgba(0, 0, 0, 0.8); /* 添加半透明背景，确保导航栏可见 */
  backdrop-filter: blur(8px); /* 添加背景模糊效果 */
}

.tab-list {
  display: flex;
  gap: 2rem;
}

.tab-item {
  cursor: pointer;
  color: #a3a3a3; // gray-400
  &.active {
    color: #fff;
    border-bottom: 2px solid #ef4444; // red-500
    padding-bottom: 0.25rem;
  }
}

.tab-title {
  font-size: 1.125rem; // text-lg
  font-weight: 500; // font-medium
}

.nav-btn {
  position: absolute;
  right: 1rem;
  color: #fff;
  background: none;
  border: none;
  cursor: pointer;
}

/* 精选页面沉浸式样式 */
.text-shadow-lg {
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}
</style>
